home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume23 / pty / part05 < prev    next >
Encoding:
Internet Message Format  |  1991-01-08  |  54.5 KB

  1. Path: j.cc.purdue.edu!mentor.cc.purdue.edu!noose.ecn.purdue.edu!samsung!uunet!papaya.bbn.com!rsalz
  2. From: rsalz@bbn.com (Rich Salz)
  3. Newsgroups: comp.sources.unix
  4. Subject: v23i035:  Run a program under a pty session, Part05/06
  5. Message-ID: <2885@litchi.bbn.com>
  6. Date: 10 Oct 90 14:17:05 GMT
  7. Organization: BBN Systems and Technologies, Cambridge MA
  8. Lines: 2318
  9. Approved: rsalz@uunet.UU.NET
  10. X-Checksum-Snefru: 60634bcd 98b8b726 3c002a75 420e8ecf
  11.  
  12. Submitted-by: Dan Bernstein <brnstnd@kramden.acf.nyu.edu>
  13. Posting-number: Volume 23, Issue 35
  14. Archive-name: pty/part05
  15.  
  16. #! /bin/sh
  17. # This is a shell archive.  Remove anything before this line, then feed it
  18. # into a shell via "sh file" or similar.  To overwrite existing files,
  19. # type "sh file -c".
  20. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  21. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  22. # Contents:  CHANGES Makefile err.c file.h.old globals.c misc.c
  23. #   patch/igntt.c pty.h sig.h sock.h tty.h util/biff.1 util/condom.1
  24. #   util/disconnect.1 util/disconnect.c util/exclon.1 util/lock.1
  25. #   util/lock.c util/mesg.1 util/mesg.c util/reconnect.1
  26. #   util/reconnect.c util/script.1 util/script.tidy.1 util/sess.1
  27. #   util/sesskill.1 util/sesskill.c util/sesslist.1 util/sessname.1
  28. #   util/sessname.c util/sessutil.h util/u.1 util/u.c util/wall.1
  29. #   util/wall.c util/who.1 util/who.c util/write.1
  30. # Wrapped by rsalz@litchi.bbn.com on Wed Oct 10 10:11:41 1990
  31. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  32. echo If this archive is complete, you will see the following message:
  33. echo '          "shar: End of archive 5 (of 6)."'
  34. if test -f 'CHANGES' -a "${1}" != "-c" ; then 
  35.   echo shar: Will not clobber existing file \"'CHANGES'\"
  36. else
  37.   echo shar: Extracting \"'CHANGES'\" \(1470 characters\)
  38.   sed "s/^X//" >'CHANGES' <<'END_OF_FILE'
  39. X9/9/90: Patch 1.
  40. X9/9/90: Put list of all known problems into README. Also some todos.
  41. X9/9/90: Fixed pty -xc bug.
  42. X
  43. X8/22/90: Packaged for comp.sources.unix, hopefully for good this time.
  44. X8/21/90: pty 3.001.
  45. X
  46. X8/21/90: INSTALL changed a bit.
  47. X8/21/90: FILES, INSTALLREADABLE, QUESTIONS.
  48. X8/21/90: Removed extraneous n, from commented-out FD_ZERO in file.h.old.
  49. X8/21/90: Used $(CC) and $(NROFF) where appropriate.
  50. X8/21/90: Shortened long Makefile lines.
  51. X8/21/90: Switched util/exclon.1 and util/excloff.1 to correct spots.
  52. X8/21/90: Included COPYRIGHT.
  53. X8/21/90: Corrected \n use in a few strings.
  54. X8/21/90: Fixed documentation of -0.
  55. X8/21/90: Fixed bug in NO_FDPASSING reconnect code.
  56. X8/21/90: Completely updated patch directory for new telnet.
  57. X
  58. X6/11/90: Packaged for comp.sources.unix.
  59. X6/1/90: pty 3.0.
  60. X
  61. X5/24/90: who.
  62. X5/23/90: lock, exclon, excloff, tiocsti, script, sess, script.tidy.
  63. X5/19/90: All working. On to the utilities...
  64. X5/12/90: What would it take to use vfork() safely?
  65. X5/12/90: -xe destroys csh, not just more. Amusing. -xE default, I guess.
  66. X5/12/90: Separated out texts.c, globals.c, sig.c.
  67. X5/12/90: Separated out configuration into config.h (as well as Makefile).
  68. X5/11/90: Passes lint -haxc, except bzero and some correct char * casts. Grrrr.
  69. X5/11/90: Removed last traces of structure copying/comparing. Sigh.
  70. X5/10/90: Mostly done. Still needs utmp, other security, ctrlr passing.
  71. X5/6/90: Progress. Chug chug chug.
  72. X5/1/90: Begin complete rewrite for version 3.0.
  73. END_OF_FILE
  74.   if test 1470 -ne `wc -c <'CHANGES'`; then
  75.     echo shar: \"'CHANGES'\" unpacked with wrong size!
  76.   fi
  77.   # end of 'CHANGES'
  78. fi
  79. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  80.   echo shar: Will not clobber existing file \"'Makefile'\"
  81. else
  82.   echo shar: Extracting \"'Makefile'\" \(1585 characters\)
  83.   sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  84. XCC=cc
  85. XCCOPTS=-O2 -s
  86. X
  87. XNROFF=nroff
  88. XNROFFOPTS=-man
  89. X
  90. Xdefault: all
  91. X
  92. Xall: pty pty.man
  93. X
  94. Xshar: pty.shar
  95. X
  96. Xpty: pty.o sigler.o master.o slave.o err.o tty.o texts.o sig.o globals.o logs.o sock.o misc.o Makefile
  97. X    $(CC) $(CCOPTS) -o pty texts.o globals.o pty.o sigler.o master.o slave.o err.o tty.o sig.o logs.o sock.o misc.o
  98. X
  99. Xpty.o: pty.c pty.h getopt.h sigler.h master.h slave.h err.h tty.h config.h texts.h sig.h logs.h file.h misc.h Makefile
  100. X    $(CC) $(CCOPTS) -c pty.c
  101. X
  102. Xsigler.o: sigler.c pty.h sigler.h config.h sig.h sock.h file.h err.h misc.h Makefile
  103. X    $(CC) $(CCOPTS) -c sigler.c
  104. X
  105. Xmaster.o: master.c pty.h master.h err.h config.h sig.h tty.h file.h logs.h sock.h misc.h Makefile
  106. X    $(CC) $(CCOPTS) -c master.c
  107. X
  108. Xslave.o: slave.c pty.h tty.h slave.h err.h config.h sig.h file.h logs.h Makefile
  109. X    $(CC) $(CCOPTS) -c slave.c
  110. X
  111. Xerr.o: err.c err.h pty.h config.h Makefile
  112. X    $(CC) $(CCOPTS) -c err.c
  113. X
  114. Xtty.o: tty.c tty.h err.h config.h file.h Makefile
  115. X    $(CC) $(CCOPTS) -c tty.c
  116. X
  117. Xsig.o: sig.c sig.h config.h Makefile
  118. X    $(CC) $(CCOPTS) -c sig.c
  119. X
  120. Xtexts.o: texts.c texts.h config.h Makefile
  121. X    $(CC) $(CCOPTS) -c texts.c
  122. X
  123. Xglobals.o: globals.c config.h pty.h tty.h Makefile
  124. X    $(CC) $(CCOPTS) -c globals.c
  125. X
  126. Xlogs.o: logs.c config.h pty.h file.h Makefile
  127. X    $(CC) $(CCOPTS) -c logs.c
  128. X
  129. Xsock.o: sock.c config.h sock.h tty.h err.h Makefile
  130. X    $(CC) $(CCOPTS) -c sock.c
  131. X
  132. Xmisc.o: misc.c config.h pty.h misc.h Makefile
  133. X    $(CC) $(CCOPTS) -c misc.c
  134. X
  135. Xpty.man: pty.1 Makefile
  136. X    $(NROFF) $(NROFFOPTS) < pty.1 > pty.man
  137. X
  138. Xpty.shar: CHANGES
  139. X    shar `cat FILES` > pty.shar
  140. X    chmod 400 pty.shar
  141. X
  142. Xpty.h: tty.h
  143. Xsig.h: config.h
  144. Xtty.h: config.h
  145. END_OF_FILE
  146.   if test 1585 -ne `wc -c <'Makefile'`; then
  147.     echo shar: \"'Makefile'\" unpacked with wrong size!
  148.   fi
  149.   # end of 'Makefile'
  150. fi
  151. if test -f 'err.c' -a "${1}" != "-c" ; then 
  152.   echo shar: Will not clobber existing file \"'err.c'\"
  153. else
  154.   echo shar: Extracting \"'err.c'\" \(1108 characters\)
  155.   sed "s/^X//" >'err.c' <<'END_OF_FILE'
  156. X/* Copyright 1990, Daniel J. Bernstein. All rights reserved. */
  157. X
  158. X#include <stdio.h>
  159. X#include "config.h"
  160. X#include "pty.h"
  161. X#include "err.h"
  162. X
  163. Xstatic void perr(e)
  164. Xint e;
  165. X{
  166. X if (!flagquiet)
  167. X  {
  168. X   if ((e < 0) || (e > sys_nerr))
  169. X     (void) fprintf(stderr,"error %d",e);
  170. X   else
  171. X     (void) fputs(sys_errlist[e],stderr);
  172. X  }
  173. X}
  174. X
  175. Xstatic void serr(s)
  176. Xchar *s;
  177. X{
  178. X if (!flagquiet)
  179. X   (void) fputs(s,stderr);
  180. X}
  181. X
  182. Xvoid warnerr2(p,s)
  183. Xchar *p;
  184. Xchar *s;
  185. X{
  186. X if (!flagquiet)
  187. X   (void) fprintf(stderr,p,s);
  188. X}
  189. X
  190. X/* Note that accounting is based on the real uid, as it should be. */
  191. X
  192. Xvoid fatal(x)
  193. Xint x;
  194. X{
  195. X (void) setreuid(uid,uid);
  196. X (void) exit(x);
  197. X /*NOTREACHED*/
  198. X}
  199. X
  200. Xvoid fatalinfo(x,s)
  201. Xint x;
  202. Xchar **s;
  203. X{
  204. X while (*s)
  205. X  {
  206. X   serr(*(s++));
  207. X   serr("\n");
  208. X  }
  209. X fatal(x);
  210. X /*NOTREACHED*/
  211. X}
  212. X
  213. Xvoid fatalerr(x,s)
  214. Xint x;
  215. Xchar *s;
  216. X{
  217. X serr(s);
  218. X fatal(x);
  219. X /*NOTREACHED*/
  220. X}
  221. X
  222. Xvoid fatalerr2p(x,p,s,e)
  223. Xint x;
  224. Xchar *p;
  225. Xchar *s;
  226. Xint e;
  227. X{
  228. X warnerr2(p,s);
  229. X serr(": ");
  230. X perr(e);
  231. X serr("\n");
  232. X fatal(x);
  233. X /*NOTREACHED*/
  234. X}
  235. X
  236. Xvoid fatalerrp(x,s,e)
  237. Xint x;
  238. Xchar *s;
  239. Xint e;
  240. X{
  241. X serr(s);
  242. X serr(": ");
  243. X perr(e);
  244. X serr("\n");
  245. X fatal(x);
  246. X /*NOTREACHED*/
  247. X}
  248. END_OF_FILE
  249.   if test 1108 -ne `wc -c <'err.c'`; then
  250.     echo shar: \"'err.c'\" unpacked with wrong size!
  251.   fi
  252.   # end of 'err.c'
  253. fi
  254. if test -f 'file.h.old' -a "${1}" != "-c" ; then 
  255.   echo shar: Will not clobber existing file \"'file.h.old'\"
  256. else
  257.   echo shar: Extracting \"'file.h.old'\" \(747 characters\)
  258.   sed "s/^X//" >'file.h.old' <<'END_OF_FILE'
  259. X/* Copyright 1990, Daniel J. Bernstein. All rights reserved. */
  260. X
  261. X#ifndef PTY_FILE_H
  262. X#define PTY_FILE_H
  263. X
  264. X#include <sys/file.h>
  265. X#ifdef BSD
  266. X#include <limits.h>
  267. X#endif
  268. X#include <fcntl.h>
  269. Xextern long lseek(); /* sigh. */
  270. X
  271. X#define NFDBITS    (sizeof(fd_mask) * NBBY)
  272. X#define    FD_SET(n,p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
  273. X#define    FD_ISSET(n,p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
  274. X#define FD_ZERO(p) bzero((caddr_t)(p),sizeof(*(p)))
  275. X
  276. X/* The following are desperation versions. Ignore pointer warnings.
  277. X#undef NFDBITS
  278. X#undef FD_SET
  279. X#undef FD_ISSET
  280. X#undef FD_ZERO
  281. X#undef fd_set
  282. X#define fd_set long
  283. X#define FD_SET(n,p) ((*p) |= (1 << (n)))
  284. X#define FD_ISSET(n,p) ((*p) & (1 << (n)))
  285. X#define FD_ZERO(p) (*p = 0L)
  286. X*/
  287. X
  288. X#endif
  289. END_OF_FILE
  290.   if test 747 -ne `wc -c <'file.h.old'`; then
  291.     echo shar: \"'file.h.old'\" unpacked with wrong size!
  292.   fi
  293.   # end of 'file.h.old'
  294. fi
  295. if test -f 'globals.c' -a "${1}" != "-c" ; then 
  296.   echo shar: Will not clobber existing file \"'globals.c'\"
  297. else
  298.   echo shar: Extracting \"'globals.c'\" \(958 characters\)
  299.   sed "s/^X//" >'globals.c' <<'END_OF_FILE'
  300. X/* Copyright 1990, Daniel J. Bernstein. All rights reserved. */
  301. X
  302. X#include "config.h"
  303. X#include "pty.h"
  304. X
  305. Xint uid;
  306. Xint euid;
  307. Xint pid;
  308. Xint pgrp;
  309. Xlong date;
  310. Xchar *username;
  311. X
  312. Xint fdin = -1;
  313. Xint fdout = -1;
  314. Xint fdmty = -1;
  315. Xint fdsty = -1;
  316. Xint fdtty = -1;
  317. Xint fdre = -1;
  318. Xint fdpass = -1;
  319. X
  320. Xint flagquiet = 0;
  321. Xint flagdetached = 0;
  322. Xint flagjobctrl = 1;
  323. Xint flagttymodes = 1;
  324. Xint flagsameerr = 0;
  325. Xint flagfdpass = 0;
  326. Xint flagsession = 0;
  327. Xint flagverbose = 0;
  328. X
  329. Xint flagxchown = 0;
  330. Xint flagxutmp = 0;
  331. Xint flagxwtmp = 0;
  332. Xint flagxexcl = 0; /* should be 1, but that would break write & friends */
  333. Xint flagxerrwo = 0; /* should be 1, but that would break csh & more */
  334. Xint flagxchkopen = 1;
  335. Xint flagxskipopen = 0;
  336. Xint flagxrandom = 1; /* random pty searching: worth the effort */
  337. Xint flagxsetuid = 1;
  338. X
  339. X#include "tty.h"
  340. X
  341. Xstruct ttymodes tmotty; /* original tty modes */
  342. Xstruct ttymodes tmochartty; /* tty in character mode */
  343. Xstruct ttymodes tmopty; /* original pty modes */
  344. END_OF_FILE
  345.   if test 958 -ne `wc -c <'globals.c'`; then
  346.     echo shar: \"'globals.c'\" unpacked with wrong size!
  347.   fi
  348.   # end of 'globals.c'
  349. fi
  350. if test -f 'misc.c' -a "${1}" != "-c" ; then 
  351.   echo shar: Will not clobber existing file \"'misc.c'\"
  352. else
  353.   echo shar: Extracting \"'misc.c'\" \(1442 characters\)
  354.   sed "s/^X//" >'misc.c' <<'END_OF_FILE'
  355. X/* Copyright 1990, Daniel J. Bernstein. All rights reserved. */
  356. X
  357. X#include "config.h"
  358. X#include <strings.h>
  359. X#include <stdio.h>
  360. X#include <pwd.h>
  361. Xextern char *getenv(); /* grrrr */
  362. Xextern char *ttyname(); /* grrrr */
  363. X#include "pty.h"
  364. X#include "misc.h"
  365. X
  366. Xint sessdir()
  367. X{
  368. X char suid[10];
  369. X char *home;
  370. X
  371. X if (flagxsetuid)
  372. X  {
  373. X   if (chdir(PTYDIR) == -1)
  374. X     return -1;
  375. X  }
  376. X else
  377. X  {
  378. X   if ((home = getenv("HOME")) == 0)
  379. X     return -1;
  380. X   else if (chdir(home) == -1)
  381. X     return -1;
  382. X   else if ((chdir(".pty") == -1)
  383. X          &&((mkdir(".pty",0700) == -1)
  384. X           ||(chdir(".pty") == -1)))
  385. X          return -1;
  386. X  }
  387. X
  388. X (void) sprintf(suid,"%d",uid);
  389. X if ((chdir(suid) == -1)
  390. X   &&((mkdir(suid,0700) == -1)
  391. X    ||(chdir(suid) == -1)))
  392. X   return -1;
  393. X return 0;
  394. X}
  395. X
  396. Xchar *real_ttyname(fd)
  397. Xint fd; /* first guess; should be /dev/tty */
  398. X{
  399. X char *ttyn;
  400. X
  401. X if ((ttyn = ttyname(fd))
  402. X   &&(strcmp(ttyn,"/dev/tty")))
  403. X  {
  404. X   /* This would actually happen if opening /dev/tty converted into */
  405. X   /* opening the actual terminal device---which would be nice. */
  406. X   return ttyn;
  407. X  }
  408. X /* So much for nice tries. */
  409. X for (fd = getdtablesize();fd >= 0;fd--)
  410. X  {
  411. X   if ((ttyn = ttyname(fd))
  412. X     &&(strcmp(ttyn,"/dev/tty")))
  413. X     return ttyn;
  414. X  }
  415. X return (char *) 0;
  416. X}
  417. X
  418. Xstatic struct passwd *pw;
  419. Xstatic char nopwun[12];
  420. X
  421. Xvoid setusername()
  422. X{
  423. X if (pw = getpwuid(uid))
  424. X   username = pw->pw_name;
  425. X else
  426. X  {
  427. X   (void) sprintf(nopwun,"%d",uid);
  428. X   username = nopwun;
  429. X  }
  430. X}
  431. END_OF_FILE
  432.   if test 1442 -ne `wc -c <'misc.c'`; then
  433.     echo shar: \"'misc.c'\" unpacked with wrong size!
  434.   fi
  435.   # end of 'misc.c'
  436. fi
  437. if test -f 'patch/igntt.c' -a "${1}" != "-c" ; then 
  438.   echo shar: Will not clobber existing file \"'patch/igntt.c'\"
  439. else
  440.   echo shar: Extracting \"'patch/igntt.c'\" \(285 characters\)
  441.   sed "s/^X//" >'patch/igntt.c' <<'END_OF_FILE'
  442. X#include <signal.h>
  443. X
  444. Xmain(argc,argv)
  445. Xint argc;
  446. Xchar *argv[];
  447. X{
  448. X switch (fork())
  449. X  {
  450. X   case -1: exit(1);
  451. X   case 0: break;
  452. X   default: exit(0);
  453. X  }
  454. X (void) signal(SIGTTOU,SIG_IGN);
  455. X (void) signal(SIGTTIN,SIG_IGN);
  456. X (void) sleep(1);
  457. X (void) execvp(argv[1],argv + 1);
  458. X (void) exit(1);
  459. X}
  460. END_OF_FILE
  461.   if test 285 -ne `wc -c <'patch/igntt.c'`; then
  462.     echo shar: \"'patch/igntt.c'\" unpacked with wrong size!
  463.   fi
  464.   # end of 'patch/igntt.c'
  465. fi
  466. if test -f 'pty.h' -a "${1}" != "-c" ; then 
  467.   echo shar: Will not clobber existing file \"'pty.h'\"
  468. else
  469.   echo shar: Extracting \"'pty.h'\" \(1721 characters\)
  470.   sed "s/^X//" >'pty.h' <<'END_OF_FILE'
  471. X/* Copyright 1990, Daniel J. Bernstein. All rights reserved. */
  472. X
  473. X#ifndef PTY_H
  474. X#define PTY_H
  475. X
  476. Xextern int uid;
  477. Xextern int euid;
  478. Xextern int pid;
  479. Xextern int pgrp;
  480. Xextern long date;
  481. Xextern char *username;
  482. X
  483. Xextern int fdin; /* input */
  484. Xextern int fdout; /* output */
  485. Xextern int fdmty; /* master side of pty */
  486. Xextern int fdsty; /* slave side of pty */
  487. Xextern int fdtty; /* current tty, if connected to one, or -1 */
  488. Xextern int fdre; /* for reconnecting and fd passing, or -1 */
  489. Xextern int fdpass; /* for passing master side up to controller */
  490. X
  491. Xextern int flagquiet; /* -q, don't make any noises at all */
  492. Xextern int flagdetached; /* -d, we are detached to start */
  493. Xextern int flagjobctrl; /* -j, we can stop/start */
  494. Xextern int flagttymodes; /* -t, we change modes of original tty */
  495. Xextern int flagsameerr; /* -e (3), we leave fds 2 (3) and up alone */
  496. Xextern int flagfdpass; /* -fn, we pass master side up fd n */
  497. Xextern int flagsession; /* -s, we can disconnect & reconnect */
  498. Xextern int flagverbose; /* -v, complain about everything */
  499. X
  500. Xextern int flagxchown; /* -xc, change owner of pty */
  501. Xextern int flagxutmp; /* -xu, add entry to utmp */
  502. Xextern int flagxwtmp; /* -xw, add entry to wtmp */
  503. Xextern int flagxexcl; /* -xx, set exclusive use */
  504. Xextern int flagxerrwo; /* -xe, make stderr write-only */
  505. Xextern int flagxchkopen; /* -xn, check if anyone has pty open */
  506. Xextern int flagxskipopen; /* -xo, skip if anyone has pty open */
  507. Xextern int flagxrandom; /* -xr, search through ptys randomly */
  508. Xextern int flagxsetuid; /* -xs, we're running setuid */
  509. X
  510. X#include "tty.h"
  511. X
  512. Xextern struct ttymodes tmotty;
  513. Xextern struct ttymodes tmochartty;
  514. Xextern struct ttymodes tmopty;
  515. X
  516. X#define copy(dst,src,num) bcopy(src,dst,num)
  517. X
  518. X#endif
  519. END_OF_FILE
  520.   if test 1721 -ne `wc -c <'pty.h'`; then
  521.     echo shar: \"'pty.h'\" unpacked with wrong size!
  522.   fi
  523.   # end of 'pty.h'
  524. fi
  525. if test -f 'sig.h' -a "${1}" != "-c" ; then 
  526.   echo shar: Will not clobber existing file \"'sig.h'\"
  527. else
  528.   echo shar: Extracting \"'sig.h'\" \(565 characters\)
  529.   sed "s/^X//" >'sig.h' <<'END_OF_FILE'
  530. X/* Copyright 1990, Daniel J. Bernstein. All rights reserved. */
  531. X
  532. X#ifndef PTY_SIG_H
  533. X#define PTY_SIG_H
  534. X
  535. X#include "config.h"
  536. X#include <signal.h>
  537. X
  538. Xtypedef void (*sig_handler)();
  539. Xtypedef SIGRET_TYPE (*sig_syshandler)();
  540. X
  541. Xextern void nothing();
  542. X
  543. X#define SIGNUM 32
  544. Xtypedef int sig_num;
  545. X
  546. Xextern void sig_init();
  547. Xextern void sig_restore();
  548. X
  549. Xextern void sig_ignore();
  550. Xextern void sig_default();
  551. Xextern void sig_handle();
  552. X
  553. X#ifdef SIGINTERRUPT
  554. Xextern void sig_interrupt();
  555. X#endif
  556. X
  557. Xextern void sig_sethandler();
  558. X
  559. Xextern void sig_startring();
  560. Xextern void sig_stopring();
  561. X
  562. X#endif
  563. END_OF_FILE
  564.   if test 565 -ne `wc -c <'sig.h'`; then
  565.     echo shar: \"'sig.h'\" unpacked with wrong size!
  566.   fi
  567.   # end of 'sig.h'
  568. fi
  569. if test -f 'sock.h' -a "${1}" != "-c" ; then 
  570.   echo shar: Will not clobber existing file \"'sock.h'\"
  571. else
  572.   echo shar: Extracting \"'sock.h'\" \(579 characters\)
  573.   sed "s/^X//" >'sock.h' <<'END_OF_FILE'
  574. X/* Copyright 1990, Daniel J. Bernstein. All rights reserved. */
  575. X
  576. X#ifndef PTY_SOCK_H
  577. X#define PTY_SOCK_H
  578. X
  579. Xextern int pty_readsock();
  580. Xextern int pty_writesock();
  581. Xextern int pty_acceptsock();
  582. X
  583. X/* -1 fail, 0 success */
  584. Xextern int pty_putgetstr();
  585. Xextern int pty_putgetfd();
  586. Xextern int pty_putgetonefd();
  587. Xextern int pty_putgetint();
  588. Xextern int pty_putgettty();
  589. Xextern int pty_getch();
  590. X
  591. X/* -1 fail, 0 success, 1 refused */
  592. Xextern int pty_sendstr();
  593. Xextern int pty_sendfd();
  594. Xextern int pty_sendonefd();
  595. Xextern int pty_sendint();
  596. Xextern int pty_sendtty();
  597. Xextern int pty_putch();
  598. X
  599. X#endif
  600. END_OF_FILE
  601.   if test 579 -ne `wc -c <'sock.h'`; then
  602.     echo shar: \"'sock.h'\" unpacked with wrong size!
  603.   fi
  604.   # end of 'sock.h'
  605. fi
  606. if test -f 'tty.h' -a "${1}" != "-c" ; then 
  607.   echo shar: Will not clobber existing file \"'tty.h'\"
  608. else
  609.   echo shar: Extracting \"'tty.h'\" \(1104 characters\)
  610.   sed "s/^X//" >'tty.h' <<'END_OF_FILE'
  611. X/* Copyright 1990, Daniel J. Bernstein. All rights reserved. */
  612. X
  613. X#ifndef PTY_TTY_H
  614. X#define PTY_TTY_H
  615. X
  616. X#include "config.h"
  617. X#include <sgtty.h>
  618. X
  619. Xstruct ttymodes
  620. X {
  621. X  int di;
  622. X  struct sgttyb sg;
  623. X  struct tchars tc;
  624. X  long lb;
  625. X  struct ltchars lt;
  626. X#ifdef TTY_WINDOWS
  627. X  struct winsize ws;
  628. X#endif
  629. X#ifdef TTY_AUXCHARS
  630. X  struct auxchars au;
  631. X#endif
  632. X }
  633. X;
  634. X
  635. Xextern int tty_getctrl();
  636. Xextern tty_setexcl(/* int fd */);
  637. Xextern tty_setpgrp(/* int fd; int pg; */);
  638. Xextern tty_dissoc(/* int fd */);
  639. Xextern tty_getmodes(/* int fd; s ttymodes *tmo */);
  640. Xextern tty_setmodes(/* int fd; s ttymodes *tmo */);
  641. Xextern tty_modifymodes(/* int fd; s ttymodes *tmonew; s ttymodes *tmoold */);
  642. X
  643. X/* The following don't do any ioctls; they just mangle internal ttymodes. */
  644. X
  645. Xextern void tty_copymodes(/* s ttymodes *tmonew; s ttymodes *tmoold */);
  646. Xextern void tty_copywin(/* s ttymodes *tmonew; s ttymodes *tmoold */);
  647. Xextern void tty_charmode(/* s ttymodes *tmo */);
  648. Xextern void tty_mungemodes(/* s ttymodes *tmo;cbreak;new;echo;crmod;raw;crt */);
  649. Xextern void tty_initmodes(/* s ttymodes *tmo;cbreak;new;echo;crmod;raw;crt */);
  650. X
  651. X#endif
  652. END_OF_FILE
  653.   if test 1104 -ne `wc -c <'tty.h'`; then
  654.     echo shar: \"'tty.h'\" unpacked with wrong size!
  655.   fi
  656.   # end of 'tty.h'
  657. fi
  658. if test -f 'util/biff.1' -a "${1}" != "-c" ; then 
  659.   echo shar: Will not clobber existing file \"'util/biff.1'\"
  660. else
  661.   echo shar: Extracting \"'util/biff.1'\" \(897 characters\)
  662.   sed "s/^X//" >'util/biff.1' <<'END_OF_FILE'
  663. X.TH biff 1
  664. X.SH NAME
  665. Xbiff \- be notified if mail arrives and who it is from
  666. X.SH SYNOPSIS
  667. X.B biff
  668. X[
  669. X.B n
  670. X] [
  671. X.B y
  672. X]
  673. X.SH DESCRIPTION
  674. XAfter
  675. X.I biff y,
  676. Xthe system will display
  677. Xthe top of incoming mail on your screen,
  678. Xas described in
  679. X.I comsat(8).
  680. X.I biff n
  681. Xturns this off.
  682. X.I biff
  683. Xapplies to your current terminal session;
  684. Xtypically you'd put a
  685. X.I biff y
  686. Xinto your
  687. X.I \&.login,
  688. X.I \&.cshrc,
  689. Xor
  690. X.I \&.profile.
  691. X.PP
  692. X.I biff
  693. Xwithout an argument tells you your current
  694. X``biffing'' status.
  695. X.PP
  696. X.I biff
  697. Xoperates asynchronously.
  698. XFor synchronous notification use the MAIL variable of
  699. X.IR sh (1)
  700. Xor the
  701. X.I mail
  702. Xvariable of
  703. X.IR csh (1).
  704. X.PP
  705. X.I biff
  706. Xrequires its input to be your terminal session
  707. X(or at least a session you own). All it really
  708. Xdoes is handle the owner-execute bit on the terminal.
  709. X.PP
  710. X.I biff
  711. Xonly looks at the first letter of its first argument.
  712. X.SH "SEE ALSO"
  713. Xcsh(1),
  714. Xsh(1),
  715. Xmail(1),
  716. Xcomsat(8C)
  717. END_OF_FILE
  718.   if test 897 -ne `wc -c <'util/biff.1'`; then
  719.     echo shar: \"'util/biff.1'\" unpacked with wrong size!
  720.   fi
  721.   # end of 'util/biff.1'
  722. fi
  723. if test -f 'util/condom.1' -a "${1}" != "-c" ; then 
  724.   echo shar: Will not clobber existing file \"'util/condom.1'\"
  725. else
  726.   echo shar: Extracting \"'util/condom.1'\" \(1176 characters\)
  727.   sed "s/^X//" >'util/condom.1' <<'END_OF_FILE'
  728. X.TH condom 1
  729. X.SH NAME
  730. Xcondom \- wrap a pseudo-terminal around a program
  731. X.SH SYNOPSIS
  732. X.B condom
  733. X.I program
  734. X.B [
  735. X.I arg ...
  736. X.B ]
  737. X.SH DESCRIPTION
  738. X.I condom,
  739. Xwhich is really just
  740. X.I pty -0,
  741. Xruns a program under a pseudo-terminal
  742. Xwith as little interpretation as possible.
  743. XThe following are the most noticeable effects of
  744. X.I condom:
  745. X.PP
  746. X1. The
  747. X.I stdio(3)
  748. Xroutines
  749. Xwill, by default,
  750. Xline-buffer their output rather than
  751. Xwaiting for a big block of output
  752. Xto accumulate.
  753. X.PP
  754. X2.
  755. X.I condom
  756. Xalways exits with exit code 0,
  757. Xprovided nothing unusual happens.
  758. X.PP
  759. X3.
  760. XThe original terminal
  761. Xis always in line-by-line,
  762. Xecho mode (or whatever mode it is
  763. Xin originally).
  764. X.PP
  765. X4.
  766. XEnd-of-file
  767. Xis ignored in the input.
  768. X(This is an inherent and unfortunate restriction
  769. Xof the current pseudo-terminal design, and may not
  770. Xbe true under other versions of
  771. X.I pty.)
  772. XIf the input really does end,
  773. X.I pty
  774. Xwill just sit around wasting CPU time.
  775. X.PP
  776. X5.
  777. XIf
  778. X.I program
  779. Xrefers to /dev/tty,
  780. Xit will see the pseudo-terminal
  781. X(i.e., its input and output)
  782. Xrather than its original terminal.
  783. X.PP
  784. X6.
  785. XVarious signals
  786. Xto
  787. X.I condom
  788. Xwill be forwarded to
  789. X.I program
  790. Xas HUPs instead.
  791. X.SH "SEE ALSO"
  792. Xpty(1),
  793. Xsetbuf(3),
  794. Xpty(4)
  795. END_OF_FILE
  796.   if test 1176 -ne `wc -c <'util/condom.1'`; then
  797.     echo shar: \"'util/condom.1'\" unpacked with wrong size!
  798.   fi
  799.   # end of 'util/condom.1'
  800. fi
  801. if test -f 'util/disconnect.1' -a "${1}" != "-c" ; then 
  802.   echo shar: Will not clobber existing file \"'util/disconnect.1'\"
  803. else
  804.   echo shar: Extracting \"'util/disconnect.1'\" \(1184 characters\)
  805.   sed "s/^X//" >'util/disconnect.1' <<'END_OF_FILE'
  806. X.TH disconnect 1
  807. X.SH NAME
  808. Xdisconnect \- disconnect current pty session
  809. X.SH SYNOPSIS
  810. X.B disconnect
  811. X.SH DESCRIPTION
  812. X.I disconnect
  813. Xdisconnects the current
  814. Xsession,
  815. Xas if the connection
  816. Xhad been hung up.
  817. XLater you can use
  818. X.I reconnect
  819. Xto get back to the session
  820. Xexactly where you left off.
  821. X.PP
  822. XBecause
  823. X.I disconnect
  824. Xdoesn't actually hang up the connection,
  825. Xbut merely severs its association with
  826. Xthe current session,
  827. Xa
  828. X.I reconnect
  829. Xon that connection will take effect
  830. Ximmediately.
  831. XThis leads to a useful trick:
  832. Xyou can switch rapidly from session
  833. X.I xx
  834. Xto disconnected session
  835. X.I yy
  836. Xby typing
  837. X.EX
  838. Xreconnect yy;disconnect
  839. X.EE
  840. XThen
  841. X.I xx
  842. Xand
  843. X.I yy
  844. Xwill be reversed,
  845. Xand you can switch back and forth without trouble.
  846. X.PP
  847. X.I xdisconnect
  848. Xworks just like
  849. X.I disconnect
  850. Xbut applies to session started with
  851. X.B\-xS.
  852. X.SH DIAGNOSTICS
  853. X.TP
  854. X.I cannot find session
  855. X.TP
  856. X.I you don't own session
  857. XThe standard input to
  858. X.I reconnect
  859. Xis not a pty session you own.
  860. X.TP
  861. X.I not child of session slave
  862. XThe parent to
  863. X.I reconnect
  864. Xis not the head process in the session.
  865. X.TP
  866. X.I cannot disconnect
  867. X.I reconnect
  868. Xis unable to communicate with
  869. Xthe
  870. Xpseudo-terminal
  871. Xmanager.
  872. X.SH "SEE ALSO"
  873. Xpty(1),
  874. Xsess(1),
  875. Xreconnect(1)
  876. END_OF_FILE
  877.   if test 1184 -ne `wc -c <'util/disconnect.1'`; then
  878.     echo shar: \"'util/disconnect.1'\" unpacked with wrong size!
  879.   fi
  880.   # end of 'util/disconnect.1'
  881. fi
  882. if test -f 'util/disconnect.c' -a "${1}" != "-c" ; then 
  883.   echo shar: Will not clobber existing file \"'util/disconnect.c'\"
  884. else
  885.   echo shar: Extracting \"'util/disconnect.c'\" \(694 characters\)
  886.   sed "s/^X//" >'util/disconnect.c' <<'END_OF_FILE'
  887. X/* Public domain. */
  888. X
  889. X#include <stdio.h>
  890. X#include <signal.h>
  891. X#include "sessutil.h"
  892. Xextern unsigned short getuid();
  893. X
  894. Xmain()
  895. X{
  896. X struct pty_session ps;
  897. X int uid;
  898. X
  899. X uid = getuid();
  900. X
  901. X if (pty_get_sess(0,uid,&ps) == -1)
  902. X  {
  903. X   (void) fputs("sessname: fatal: cannot find session\n",stderr);
  904. X   (void) exit(1);
  905. X  }
  906. X if (ps.uid != uid)
  907. X  {
  908. X   (void) fputs("sessname: fatal: you don't own session\n",stderr);
  909. X   (void) exit(1);
  910. X  }
  911. X if (ps.slavepid != getppid())
  912. X  {
  913. X   (void) fputs("sessname: fatal: not child of session slave\n",stderr);
  914. X   (void) exit(1);
  915. X  }
  916. X if (kill(ps.siglerpid,SIGUSR1) == -1)
  917. X  {
  918. X   (void) perror("sessname: fatal: cannot disconnect");
  919. X   (void) exit(1);
  920. X  }
  921. X (void) exit(0);
  922. X}
  923. END_OF_FILE
  924.   if test 694 -ne `wc -c <'util/disconnect.c'`; then
  925.     echo shar: \"'util/disconnect.c'\" unpacked with wrong size!
  926.   fi
  927.   # end of 'util/disconnect.c'
  928. fi
  929. if test -f 'util/exclon.1' -a "${1}" != "-c" ; then 
  930.   echo shar: Will not clobber existing file \"'util/exclon.1'\"
  931. else
  932.   echo shar: Extracting \"'util/exclon.1'\" \(692 characters\)
  933.   sed "s/^X//" >'util/exclon.1' <<'END_OF_FILE'
  934. X.TH excl 1
  935. X.SH NAME
  936. Xexclon, excloff \- reserve tty for exclusive use
  937. X.SH SYNOPSIS
  938. X.B exclon
  939. X.PP
  940. X.B excloff
  941. X.SH DESCRIPTION
  942. XThe
  943. X.B exclon
  944. Xcommand reserves your terminal for exclusive use with
  945. Xthe TIOCEXCL ioctl.
  946. XThis means that any process attempting to open your terminal
  947. Xwill fail, including other users attempting to write or cat,
  948. Xand including reference to /dev/tty by yourself.
  949. X.PP
  950. XTalk is not affected at all by exclon.
  951. X.PP
  952. XTo unreserve your terminal, use excloff.
  953. XIt is polite to do this at the end of a session,
  954. Xthough it is automatic when the terminal is closed.
  955. X.SH AUTHOR
  956. XI hesitate to claim authorship for a one-statement program.
  957. X.SH "SEE ALSO"
  958. Xtalk(1), stty(1), ioctl(2), tty(4)
  959. END_OF_FILE
  960.   if test 692 -ne `wc -c <'util/exclon.1'`; then
  961.     echo shar: \"'util/exclon.1'\" unpacked with wrong size!
  962.   fi
  963.   # end of 'util/exclon.1'
  964. fi
  965. if test -f 'util/lock.1' -a "${1}" != "-c" ; then 
  966.   echo shar: Will not clobber existing file \"'util/lock.1'\"
  967. else
  968.   echo shar: Extracting \"'util/lock.1'\" \(485 characters\)
  969.   sed "s/^X//" >'util/lock.1' <<'END_OF_FILE'
  970. X.TH lock 1
  971. X.SH NAME
  972. Xlock \- reserve a terminal
  973. X.SH SYNOPSIS
  974. X.B lock
  975. X.SH DESCRIPTION
  976. X.I lock
  977. Xrequests a password from the user, reads it again for verification,
  978. Xand then sits around doing nothing until the password is typed a third
  979. Xtime.
  980. X.PP
  981. XThis clone version of
  982. X.I lock
  983. Xcorrects several of the original's failings, by being much simpler:
  984. Xit doesn't accept
  985. X.I hasta la vista;
  986. Xit doesn't accept
  987. Xthe root password;
  988. Xit doesn't time out;
  989. Xand it does print a message for each bad password.
  990. END_OF_FILE
  991.   if test 485 -ne `wc -c <'util/lock.1'`; then
  992.     echo shar: \"'util/lock.1'\" unpacked with wrong size!
  993.   fi
  994.   # end of 'util/lock.1'
  995. fi
  996. if test -f 'util/lock.c' -a "${1}" != "-c" ; then 
  997.   echo shar: Will not clobber existing file \"'util/lock.c'\"
  998. else
  999.   echo shar: Extracting \"'util/lock.c'\" \(852 characters\)
  1000.   sed "s/^X//" >'util/lock.c' <<'END_OF_FILE'
  1001. X/* Public domain. */
  1002. X#include <curses.h>
  1003. X#include <signal.h>
  1004. X#include <strings.h>
  1005. X
  1006. Xmain()
  1007. X{
  1008. X char key[100];
  1009. X char key2[100];
  1010. X struct sigvec vec;
  1011. X int i;
  1012. X
  1013. X vec.sv_handler = SIG_IGN;
  1014. X vec.sv_mask = 0;
  1015. X for (i = 31;i > 0;i--)
  1016. X   (void) sigvec(i,&vec,(struct sigvec *) 0);
  1017. X (void) savetty();
  1018. X (void) crmode();
  1019. X (void) noecho();
  1020. X (void) printf("Key: ");
  1021. X if (fgets(key,sizeof(key) - 2,stdin))
  1022. X  {
  1023. X   (void) printf("\nAgain: ");
  1024. X   if (fgets(key2,sizeof(key2) - 2,stdin))
  1025. X    {
  1026. X     if (!strcmp(key,key2))
  1027. X      {
  1028. X       (void) printf("\n");
  1029. X       while ((fgets(key2,sizeof(key2),stdin) == NULL) || strcmp(key,key2))
  1030. X    {
  1031. X     (void) printf("Bad password!\n");
  1032. X     (void) sleep(1);
  1033. X    }
  1034. X      }
  1035. X     else (void) printf("\n");
  1036. X    }
  1037. X   else (void) printf("\n");
  1038. X  }
  1039. X else (void) printf("\n");
  1040. X (void) resetty();
  1041. X (void) exit(0);
  1042. X /*NOTREACHED*/
  1043. X}
  1044. END_OF_FILE
  1045.   echo shar: 20 control characters may be missing from \"'util/lock.c'\"
  1046.   if test 852 -ne `wc -c <'util/lock.c'`; then
  1047.     echo shar: \"'util/lock.c'\" unpacked with wrong size!
  1048.   fi
  1049.   # end of 'util/lock.c'
  1050. fi
  1051. if test -f 'util/mesg.1' -a "${1}" != "-c" ; then 
  1052.   echo shar: Will not clobber existing file \"'util/mesg.1'\"
  1053. else
  1054.   echo shar: Extracting \"'util/mesg.1'\" \(814 characters\)
  1055.   sed "s/^X//" >'util/mesg.1' <<'END_OF_FILE'
  1056. X.TH mesg 1
  1057. X.SH NAME
  1058. Xmesg \- permit or deny messages
  1059. X.SH SYNOPSIS
  1060. X.B mesg
  1061. X[
  1062. X.B n
  1063. X] [
  1064. X.B y
  1065. X]
  1066. X.SH DESCRIPTION
  1067. XAfter
  1068. X.I mesg y,
  1069. Xother users can
  1070. Xuse
  1071. X.I write(1)
  1072. Xor
  1073. X.I talk(1)
  1074. Xto send messages to your terminal.
  1075. X.I mesg n
  1076. Xturns this off.
  1077. X.I mesg
  1078. Xapplies to your current terminal session;
  1079. Xtypically you'd put a
  1080. X.I mesg y
  1081. Xinto your
  1082. X.I \&.login,
  1083. X.I \&.cshrc,
  1084. Xor
  1085. X.I \&.profile.
  1086. X.PP
  1087. X.I mesg
  1088. Xwithout an argument tells you your current
  1089. Xmessaging status.
  1090. X.PP
  1091. X.I mesg
  1092. Xrequires its input to be your terminal session
  1093. X(or at least a session you own). All it really
  1094. Xdoes is handle the group-write bit on the terminal.
  1095. X.PP
  1096. X.I mesg
  1097. Xonly looks at the first letter of its first argument.
  1098. X.SH "EXIT VALUE"
  1099. XWithout an argument,
  1100. X.I mesg
  1101. Xexits with value 0 if messages are receivable,
  1102. X1 if not,
  1103. X2 upon error.
  1104. X.SH "SEE ALSO"
  1105. Xwrite(1), talk(1)
  1106. END_OF_FILE
  1107.   if test 814 -ne `wc -c <'util/mesg.1'`; then
  1108.     echo shar: \"'util/mesg.1'\" unpacked with wrong size!
  1109.   fi
  1110.   # end of 'util/mesg.1'
  1111. fi
  1112. if test -f 'util/mesg.c' -a "${1}" != "-c" ; then 
  1113.   echo shar: Will not clobber existing file \"'util/mesg.c'\"
  1114. else
  1115.   echo shar: Extracting \"'util/mesg.c'\" \(1079 characters\)
  1116.   sed "s/^X//" >'util/mesg.c' <<'END_OF_FILE'
  1117. X/* Public domain. */
  1118. X
  1119. X#include <sys/types.h>
  1120. X#include <sys/stat.h>
  1121. X#include <stdio.h>
  1122. X#include "sessutil.h"
  1123. Xextern unsigned short getuid();
  1124. X
  1125. X#define FOO (void) fstat(0,&st); \
  1126. Xif (which) (void) fchmod(0,(int) (st.st_mode | 0020)); \
  1127. Xelse (void) fchmod(0,(int) (st.st_mode & ~0020));
  1128. X
  1129. Xmain(argc,argv)
  1130. Xint argc;
  1131. Xchar *argv[];
  1132. X{
  1133. X struct stat st;
  1134. X struct pty_session ps;
  1135. X int uid;
  1136. X int which;
  1137. X
  1138. X uid = getuid();
  1139. X
  1140. X if (argc == 1)
  1141. X  {
  1142. X   (void) setreuid(uid,uid);
  1143. X   (void) fstat(0,&st);
  1144. X   if (which = st.st_mode & 0020)
  1145. X     (void) printf("is y\n");
  1146. X   else
  1147. X     (void) printf("is n\n");
  1148. X   (void) exit(1 - which);
  1149. X  }
  1150. X else
  1151. X  {
  1152. X   switch(argv[1][0])
  1153. X    {
  1154. X     case 'y': which = 1; break;
  1155. X     case 'n': which = 0; break;
  1156. X     default: (void) fprintf(stderr,"mesg: usage: mesg [y] [n]\n"); exit(1);
  1157. X    }
  1158. X   if (pty_get_sess(0,uid,&ps) == -1)
  1159. X    {
  1160. X     (void) setreuid(uid,uid);
  1161. X     FOO
  1162. X    }
  1163. X   else
  1164. X     if (ps.uid != uid)
  1165. X       (void) fprintf(stderr,"not your session\n");
  1166. X     else
  1167. X      {
  1168. X       FOO
  1169. X       (void) setreuid(uid,uid);
  1170. X       FOO
  1171. X      }
  1172. X  }
  1173. X (void) exit(0);
  1174. X}
  1175. END_OF_FILE
  1176.   if test 1079 -ne `wc -c <'util/mesg.c'`; then
  1177.     echo shar: \"'util/mesg.c'\" unpacked with wrong size!
  1178.   fi
  1179.   # end of 'util/mesg.c'
  1180. fi
  1181. if test -f 'util/reconnect.1' -a "${1}" != "-c" ; then 
  1182.   echo shar: Will not clobber existing file \"'util/reconnect.1'\"
  1183. else
  1184.   echo shar: Extracting \"'util/reconnect.1'\" \(1604 characters\)
  1185.   sed "s/^X//" >'util/reconnect.1' <<'END_OF_FILE'
  1186. X.TH reconnect 1
  1187. X.SH NAME
  1188. Xreconnect \- reconnect to a pty session
  1189. X.SH SYNOPSIS
  1190. X.B reconnect
  1191. X.I sn
  1192. X.SH DESCRIPTION
  1193. X.I reconnect
  1194. X.I sn
  1195. Xmeans
  1196. X``When this session finishes or is disconnected,
  1197. Xreconnect to the session named
  1198. X.I sn.''
  1199. XThis lets you get back to a
  1200. Xsession abandoned by
  1201. X.I disconnect
  1202. Xor by a previously hung up connection.
  1203. X.PP
  1204. XIf you are not currently
  1205. Xunder a
  1206. X.I pty
  1207. Xsession,
  1208. Xor if you would like to reconnect
  1209. Ximmediately without waiting for
  1210. Xthe current session to finish,
  1211. Xyou can use
  1212. X.EX
  1213. Xsess reconnect xx
  1214. X.EE
  1215. X.PP
  1216. XIf you leave out
  1217. Xa session name,
  1218. Xthe connection will simply drop
  1219. Xwhen its association with the
  1220. Xcurrent session is severed.
  1221. XThis is the normal behavior.
  1222. X.PP
  1223. XA
  1224. X.I reconnect
  1225. Xreplaces each that came before it.
  1226. X.PP
  1227. XOn systems
  1228. Xwhere
  1229. X.I pty
  1230. Xuses
  1231. Xfile descriptor passing,
  1232. Xa reconnected session is
  1233. Xhandled just as efficiently as
  1234. Xa session connected for the first time.
  1235. X.PP
  1236. X.I xreconnect
  1237. Xworks just like
  1238. X.I reconnect
  1239. Xbut handles sessions
  1240. Xstarted with
  1241. X.B\-xS.
  1242. X.SH DIAGNOSTICS
  1243. X.TP
  1244. X.I cannot find session
  1245. X.TP
  1246. X.I you don't own session
  1247. XThe standard input to
  1248. X.I reconnect
  1249. Xis not a pty session you own.
  1250. X.TP
  1251. X.I cannot find reconnector
  1252. X.I sn
  1253. Xis not the name of a currently disconnected session
  1254. Xthat you own.
  1255. X.TP
  1256. X.I cannot set reconnector
  1257. X.TP
  1258. X.I cannot unset reconnector
  1259. X.I reconnect
  1260. Xis unable to change this connection's
  1261. Xreconnection status.
  1262. X.TP
  1263. X.I xx set, will reconnect after yy drops
  1264. X.TP
  1265. X.I xx unset, won't reconnect after yy drops
  1266. XSuccess: you are using session
  1267. X.I yy,
  1268. Xand will reconnect to session
  1269. X.I xx
  1270. X(or to no session at all)
  1271. Xwhen this one drops.
  1272. X.SH "SEE ALSO"
  1273. Xpty(1),
  1274. Xsess(1),
  1275. Xdisconnect(1)
  1276. END_OF_FILE
  1277.   if test 1604 -ne `wc -c <'util/reconnect.1'`; then
  1278.     echo shar: \"'util/reconnect.1'\" unpacked with wrong size!
  1279.   fi
  1280.   # end of 'util/reconnect.1'
  1281. fi
  1282. if test -f 'util/reconnect.c' -a "${1}" != "-c" ; then 
  1283.   echo shar: Will not clobber existing file \"'util/reconnect.c'\"
  1284. else
  1285.   echo shar: Extracting \"'util/reconnect.c'\" \(1244 characters\)
  1286.   sed "s/^X//" >'util/reconnect.c' <<'END_OF_FILE'
  1287. X/* Public domain. */
  1288. X
  1289. X#include <stdio.h>
  1290. X#include <signal.h>
  1291. X#include <errno.h>
  1292. Xextern int errno;
  1293. X#include "sessutil.h"
  1294. Xextern unsigned short getuid();
  1295. X
  1296. Xmain(argc,argv)
  1297. Xint argc;
  1298. Xchar *argv[];
  1299. X{
  1300. X struct pty_session ps;
  1301. X int uid;
  1302. X
  1303. X uid = getuid();
  1304. X
  1305. X if (pty_get_sess(0,uid,&ps) == -1)
  1306. X  {
  1307. X   (void) fputs("reconnect: fatal: cannot find session\n",stderr);
  1308. X   (void) exit(1);
  1309. X  }
  1310. X if (ps.uid != uid)
  1311. X  {
  1312. X   (void) fputs("reconnect: fatal: you don't own session\n",stderr);
  1313. X   (void) exit(1);
  1314. X  }
  1315. X if (argv[1])
  1316. X   if (pty_get_rebyext(argv[1][0],argv[1][1],uid) == -1)
  1317. X    {
  1318. X     (void) fputs("reconnect: fatal: cannot find reconnector\n",stderr);
  1319. X     (void) exit(1);
  1320. X    }
  1321. X if (argv[1])
  1322. X  {
  1323. X   if (pty_set_sig(argv[1][0],argv[1][1],uid,&ps) == -1)
  1324. X    {
  1325. X     (void) fputs("reconnect: fatal: cannot set reconnector\n",stderr);
  1326. X     (void) exit(1);
  1327. X    }
  1328. X   (void) printf("reconnect: %c%c set, will reconnect after %c%c drops\n",
  1329. X         argv[1][0],argv[1][1],ps.ext1,ps.ext2);
  1330. X  }
  1331. X else
  1332. X  {
  1333. X   if (pty_unset_sig(uid,&ps) == -1)
  1334. X    {
  1335. X     (void) fputs("reconnect: fatal: cannot unset reconnector\n",stderr);
  1336. X     (void) exit(1);
  1337. X    }
  1338. X   (void) printf("reconnect: unset, won't reconnect after %c%c drops\n",
  1339. X         ps.ext1,ps.ext2);
  1340. X  }
  1341. X (void) exit(0);
  1342. X}
  1343. END_OF_FILE
  1344.   if test 1244 -ne `wc -c <'util/reconnect.c'`; then
  1345.     echo shar: \"'util/reconnect.c'\" unpacked with wrong size!
  1346.   fi
  1347.   # end of 'util/reconnect.c'
  1348. fi
  1349. if test -f 'util/script.1' -a "${1}" != "-c" ; then 
  1350.   echo shar: Will not clobber existing file \"'util/script.1'\"
  1351. else
  1352.   echo shar: Extracting \"'util/script.1'\" \(1100 characters\)
  1353.   sed "s/^X//" >'util/script.1' <<'END_OF_FILE'
  1354. X.TH script 1
  1355. X.SH NAME
  1356. Xscript \- make typescript of terminal session
  1357. X.SH SYNOPSIS
  1358. X.B script
  1359. X[
  1360. X.B \-a
  1361. X] [
  1362. X.I file
  1363. X]
  1364. X.SH DESCRIPTION
  1365. X.I script
  1366. Xmakes a typescript of everything printed on your terminal.
  1367. XThe typescript is written to
  1368. X.I file,
  1369. Xor appended to
  1370. X.I file
  1371. Xif the
  1372. X.B \-a
  1373. Xoption is given.
  1374. XYou can print it later with
  1375. X.I lpr.
  1376. XIf you don't give a filename,
  1377. Xthe typescript is saved in the file
  1378. X.I typescript.
  1379. X.PP
  1380. XActually,
  1381. Xthis clone version of
  1382. X.I script
  1383. Xjust passes its options through to
  1384. X.I tee,
  1385. Xso you can list multiple files if you want.
  1386. X.PP
  1387. X.I script
  1388. Xruns whatever shell is in environment variable
  1389. X.I SHELL.
  1390. XThis clone version uses
  1391. X.I pty
  1392. Xto allocate a pseudo-terminal,
  1393. Xso the session is listed in
  1394. X.I /etc/utmp,
  1395. Xand lots of things work right that
  1396. Xdidn't work in the original.
  1397. XFor example:
  1398. X.I talk(1)
  1399. Xworks;
  1400. X.I mail(1)
  1401. Xworks;
  1402. Xyou can stop and restart the shell,
  1403. Xwith
  1404. X.B control-Z
  1405. Xin
  1406. X.I sh
  1407. Xor
  1408. X.B suspend
  1409. Xin
  1410. X.I csh;
  1411. Xand so on.
  1412. X.PP
  1413. XThe script ends when the forked shell exits.
  1414. XThis clone version is more careful than the original to
  1415. Xlet every last bit of output appear.
  1416. X.SH "SEE ALSO"
  1417. Xscript.tidy(1)
  1418. END_OF_FILE
  1419.   if test 1100 -ne `wc -c <'util/script.1'`; then
  1420.     echo shar: \"'util/script.1'\" unpacked with wrong size!
  1421.   fi
  1422.   # end of 'util/script.1'
  1423. fi
  1424. if test -f 'util/script.tidy.1' -a "${1}" != "-c" ; then 
  1425.   echo shar: Will not clobber existing file \"'util/script.tidy.1'\"
  1426. else
  1427.   echo shar: Extracting \"'util/script.tidy.1'\" \(319 characters\)
  1428.   sed "s/^X//" >'util/script.tidy.1' <<'END_OF_FILE'
  1429. X.TH script.tidy 1
  1430. X.SH NAME
  1431. Xscript.tidy \- remove extra carriage returns and backspaces
  1432. X.SH SYNOPSIS
  1433. X.B script.tidy
  1434. X.SH DESCRIPTION
  1435. XThis filter
  1436. Xdoes a bit of postprocessing,
  1437. Xtypically on a typescript produced by
  1438. X.I script.
  1439. XIt removes extra carriage returns,
  1440. Xand wipes out backspaced characters.
  1441. X.SH "SEE ALSO"
  1442. Xscript(1)
  1443. END_OF_FILE
  1444.   if test 319 -ne `wc -c <'util/script.tidy.1'`; then
  1445.     echo shar: \"'util/script.tidy.1'\" unpacked with wrong size!
  1446.   fi
  1447.   # end of 'util/script.tidy.1'
  1448. fi
  1449. if test -f 'util/sess.1' -a "${1}" != "-c" ; then 
  1450.   echo shar: Will not clobber existing file \"'util/sess.1'\"
  1451. else
  1452.   echo shar: Extracting \"'util/sess.1'\" \(1184 characters\)
  1453.   sed "s/^X//" >'util/sess.1' <<'END_OF_FILE'
  1454. X.TH sess 1
  1455. X.SH NAME
  1456. Xsess \- run a program under a disconnectable pty session
  1457. X.SH SYNOPSIS
  1458. X.B sess
  1459. X.I program
  1460. X.B [
  1461. X.I arg ...
  1462. X.B ]
  1463. X.SH DESCRIPTION
  1464. X.I sess,
  1465. Xwhich is really just
  1466. X.I pty -s,
  1467. Xruns a program under a pseudo-terminal
  1468. Xsession that can be easily disconnected and reconnected,
  1469. Xeven into the middle of a pipe.
  1470. X.PP
  1471. X.I sess
  1472. Xhas all the effects of
  1473. X.I condom,
  1474. Xbut sets the original
  1475. Xterminal to character mode
  1476. Xand lets the pseudo-terminal do
  1477. Xtty processing.
  1478. XThis means that changes to the terminal modes by
  1479. X.I program
  1480. Xwill take effect,
  1481. Xthough
  1482. Xthe original modes will be
  1483. Xrestored when
  1484. X.I program
  1485. Xstops or exits.
  1486. X.PP
  1487. X.I sess
  1488. Xalso enters the user into
  1489. X/etc/utmp by default;
  1490. Xthis can be turned off with
  1491. X.B\-xU.
  1492. X.PP
  1493. XWhen
  1494. X.I sess
  1495. Xreceives a HUP signal,
  1496. Xi.e., when the connection is manually hung up,
  1497. Xit disconnects
  1498. X.I program
  1499. Xfrom the outside world
  1500. Xand waits for a
  1501. X.I reconnect.
  1502. X.PP
  1503. XSessions are named by
  1504. Xtheir pseudo-terminal extension:
  1505. Xfor example,
  1506. Xa session under /dev/ttyp5
  1507. Xhas name p5.
  1508. XYou can use
  1509. X.I sessname
  1510. Xto give them more descriptive names,
  1511. Xprinted by
  1512. X.I sesslist.
  1513. X.SH "SEE ALSO"
  1514. Xpty(1),
  1515. Xcondom(1),
  1516. Xdisconnect(1),
  1517. Xreconnect(1),
  1518. Xsessname(1),
  1519. Xsesskill(1),
  1520. Xsesslist(1),
  1521. Xsessuser(1)
  1522. END_OF_FILE
  1523.   if test 1184 -ne `wc -c <'util/sess.1'`; then
  1524.     echo shar: \"'util/sess.1'\" unpacked with wrong size!
  1525.   fi
  1526.   # end of 'util/sess.1'
  1527. fi
  1528. if test -f 'util/sesskill.1' -a "${1}" != "-c" ; then 
  1529.   echo shar: Will not clobber existing file \"'util/sesskill.1'\"
  1530. else
  1531.   echo shar: Extracting \"'util/sesskill.1'\" \(817 characters\)
  1532.   sed "s/^X//" >'util/sesskill.1' <<'END_OF_FILE'
  1533. X.TH sesskill 1
  1534. X.SH NAME
  1535. Xsesskill \- kill an outdated pty session
  1536. X.SH SYNOPSIS
  1537. X.B sesskill
  1538. X.I sn
  1539. X.SH DESCRIPTION
  1540. XNormally,
  1541. Xa disconnected pty session will
  1542. Xwait to be connected
  1543. X(and in the foreground)
  1544. Xbefore it produces output.
  1545. XEven if the program run under the session dies,
  1546. X.I pty
  1547. Xwill stick around, saving any last output.
  1548. X.I sesskill
  1549. X.I sn
  1550. Xkills the session named
  1551. X.I sn,
  1552. Xforcing it to throw away the output and exit.
  1553. X.PP
  1554. X.I xsesskill
  1555. Xis just like
  1556. X.I sesskill
  1557. Xbut applies to sessions started
  1558. Xwith
  1559. X.B\-xS.
  1560. X.SH DIAGNOSTICS
  1561. X.TP
  1562. X.I cannot find session
  1563. X.TP
  1564. X.I you don't own session
  1565. X.I sn
  1566. Xis not a session that you own.
  1567. X.TP
  1568. X.I session slave still alive
  1569. XSelf-explanatory.
  1570. X.TP
  1571. X.I cannot kill session master
  1572. X.I sesskill
  1573. Xis unable to communicate with
  1574. Xthe 
  1575. Xpseudo-terminal
  1576. Xmanager.
  1577. X.SH "SEE ALSO"
  1578. Xpty(1),
  1579. Xsess(1),
  1580. Xreconnect(1)
  1581. END_OF_FILE
  1582.   if test 817 -ne `wc -c <'util/sesskill.1'`; then
  1583.     echo shar: \"'util/sesskill.1'\" unpacked with wrong size!
  1584.   fi
  1585.   # end of 'util/sesskill.1'
  1586. fi
  1587. if test -f 'util/sesskill.c' -a "${1}" != "-c" ; then 
  1588.   echo shar: Will not clobber existing file \"'util/sesskill.c'\"
  1589. else
  1590.   echo shar: Extracting \"'util/sesskill.c'\" \(1004 characters\)
  1591.   sed "s/^X//" >'util/sesskill.c' <<'END_OF_FILE'
  1592. X/* Public domain. */
  1593. X
  1594. X#include <stdio.h>
  1595. X#include <signal.h>
  1596. X#include <errno.h>
  1597. Xextern int errno;
  1598. X#include "sessutil.h"
  1599. Xextern unsigned short getuid();
  1600. X
  1601. Xmain(argc,argv)
  1602. Xint argc;
  1603. Xchar *argv[];
  1604. X{
  1605. X struct pty_session ps;
  1606. X int uid;
  1607. X
  1608. X uid = getuid();
  1609. X
  1610. X if (!argv[1])
  1611. X  {
  1612. X   (void) fputs("Usage: sesskill ext\n",stderr);
  1613. X   (void) exit(1);
  1614. X  }
  1615. X if (pty_get_sessbyext(argv[1][0],argv[1][1],uid,&ps) == -1)
  1616. X  {
  1617. X   (void) fputs("sesskill: fatal: cannot find session\n",stderr);
  1618. X   (void) exit(1);
  1619. X  }
  1620. X if (ps.uid != uid)
  1621. X  {
  1622. X   (void) fputs("sesskill: fatal: you don't own session\n",stderr);
  1623. X   (void) exit(1);
  1624. X  }
  1625. X if ((kill(ps.slavepid,0) != -1) || (errno != ESRCH))
  1626. X  {
  1627. X   /* If all goes wrong, this test could allow a denial of service */
  1628. X   /* attack. Sigh. */
  1629. X   (void) fputs("sesskill: fatal: session slave still alive\n",stderr);
  1630. X   (void) exit(1);
  1631. X  }
  1632. X if (kill(ps.masterpid,SIGXCPU) == -1)
  1633. X  {
  1634. X   (void) perror("sesskill: fatal: cannot kill session master");
  1635. X   (void) exit(1);
  1636. X  }
  1637. X (void) exit(0);
  1638. X}
  1639. END_OF_FILE
  1640.   if test 1004 -ne `wc -c <'util/sesskill.c'`; then
  1641.     echo shar: \"'util/sesskill.c'\" unpacked with wrong size!
  1642.   fi
  1643.   # end of 'util/sesskill.c'
  1644. fi
  1645. if test -f 'util/sesslist.1' -a "${1}" != "-c" ; then 
  1646.   echo shar: Will not clobber existing file \"'util/sesslist.1'\"
  1647. else
  1648.   echo shar: Extracting \"'util/sesslist.1'\" \(1155 characters\)
  1649.   sed "s/^X//" >'util/sesslist.1' <<'END_OF_FILE'
  1650. X.TH sesslist 1
  1651. X.SH NAME
  1652. Xsesslist \- list all pty sessions you own
  1653. X.SH SYNOPSIS
  1654. X.B sesslist
  1655. X.SH DESCRIPTION
  1656. X.I sesslist
  1657. Xinterprets each file in the
  1658. X.I pty
  1659. Xsession directory,
  1660. Xprinting the results on the standard output.
  1661. X.PP
  1662. X``session sn disconnected''
  1663. Xmeans that the named session is waiting for a
  1664. X.I reconnect.
  1665. X.PP
  1666. X``session sn sigler p1 master p2 slave p3''
  1667. Xmeans that there is a
  1668. X.I pty
  1669. Xsession named
  1670. X.I sn.
  1671. XThe session program is
  1672. X``slave'' process p3,
  1673. Xcontrolled by a
  1674. X``master'' process p2,
  1675. Xcurrently connected to a
  1676. X``signaller'' process p1.
  1677. X(If the session is disconnected,
  1678. Xthe signaller is not meaningful.)
  1679. XAt the end of the line,
  1680. X.I sesslist
  1681. Xwill print any name provided by
  1682. X.I sessname.
  1683. X.PP
  1684. X``session xx will drop into session yy''
  1685. Xmeans that the current connection to session xx
  1686. Xwill reconnect to session yy when it is severed.
  1687. X.PP
  1688. X.I xsesslist
  1689. Xis just like
  1690. X.I sesslist
  1691. Xbut applies to sessions started
  1692. Xwith
  1693. X.B\-xS.
  1694. X.SH DIAGNOSTICS
  1695. X.TP
  1696. X.I unknown file type
  1697. X.I sesslist
  1698. Xdoes not understand a file name.
  1699. X.TP
  1700. X.I cannot open
  1701. X.TP
  1702. X.I cannot open
  1703. XThese should not happen.
  1704. XReport them to your system administrator.
  1705. X.SH "SEE ALSO"
  1706. Xpty(1),
  1707. Xsess(1),
  1708. Xsessname(1)
  1709. END_OF_FILE
  1710.   if test 1155 -ne `wc -c <'util/sesslist.1'`; then
  1711.     echo shar: \"'util/sesslist.1'\" unpacked with wrong size!
  1712.   fi
  1713.   # end of 'util/sesslist.1'
  1714. fi
  1715. if test -f 'util/sessname.1' -a "${1}" != "-c" ; then 
  1716.   echo shar: Will not clobber existing file \"'util/sessname.1'\"
  1717. else
  1718.   echo shar: Extracting \"'util/sessname.1'\" \(1007 characters\)
  1719.   sed "s/^X//" >'util/sessname.1' <<'END_OF_FILE'
  1720. X.TH sessname 1
  1721. X.SH NAME
  1722. Xsessname \- provide a more descriptive name for the current pty session
  1723. X.SH SYNOPSIS
  1724. X.B sessname
  1725. X[
  1726. X.I name
  1727. X]
  1728. X.SH DESCRIPTION
  1729. X.I sessname
  1730. Xadds
  1731. X.I name
  1732. Xto the information listed by
  1733. X.I sesslist.
  1734. XDon't confuse this extra name with
  1735. Xthe base name of the session,
  1736. Xwhich is the last two characters of the
  1737. Xpseudo-terminal filename.
  1738. X.PP
  1739. XWithout an argument,
  1740. X.I sessname
  1741. Xprints the name of the current session.
  1742. X.PP
  1743. X.I xsessname
  1744. Xis just like
  1745. X.I sessname
  1746. Xbut applies to sessions started
  1747. Xwith
  1748. X.B\-xS.
  1749. X.SH DIAGNOSTICS
  1750. X.TP
  1751. X.I cannot find session
  1752. X.TP
  1753. X.I you don't own session
  1754. XThe standard input to
  1755. X.I sessname
  1756. Xis not a session that you own.
  1757. X.TP
  1758. X.I not child of session slave
  1759. XThe parent to
  1760. X.I sessname
  1761. Xis not the head process in the session.
  1762. X.TP
  1763. X.I renaming failed
  1764. X.I sessname
  1765. Xis unable to set the long name of the session.
  1766. XThis shouldn't happen.
  1767. X.SH RESTRICTIONS
  1768. X.I name
  1769. Xis limited to 100 characters.
  1770. X.PP
  1771. XAt the moment,
  1772. Xthere's no way to unname a session.
  1773. X.SH "SEE ALSO"
  1774. Xpty(1),
  1775. Xsess(1),
  1776. Xsesslist(1)
  1777. END_OF_FILE
  1778.   if test 1007 -ne `wc -c <'util/sessname.1'`; then
  1779.     echo shar: \"'util/sessname.1'\" unpacked with wrong size!
  1780.   fi
  1781.   # end of 'util/sessname.1'
  1782. fi
  1783. if test -f 'util/sessname.c' -a "${1}" != "-c" ; then 
  1784.   echo shar: Will not clobber existing file \"'util/sessname.c'\"
  1785. else
  1786.   echo shar: Extracting \"'util/sessname.c'\" \(1052 characters\)
  1787.   sed "s/^X//" >'util/sessname.c' <<'END_OF_FILE'
  1788. X/* Public domain. */
  1789. X
  1790. X#include <stdio.h>
  1791. X#include <strings.h>
  1792. X#include "sessutil.h"
  1793. Xextern unsigned short getuid();
  1794. X
  1795. Xmain(argc,argv)
  1796. Xint argc;
  1797. Xchar *argv[];
  1798. X{
  1799. X struct pty_session ps;
  1800. X int uid;
  1801. X char buf[100];
  1802. X int s;
  1803. X
  1804. X uid = getuid();
  1805. X
  1806. X if (pty_get_sess(0,uid,&ps) == -1)
  1807. X  {
  1808. X   (void) fputs("sessname: fatal: cannot find session\n",stderr);
  1809. X   (void) exit(1);
  1810. X  }
  1811. X if (ps.uid != uid)
  1812. X  {
  1813. X   (void) fputs("sessname: fatal: you don't own session\n",stderr);
  1814. X   (void) exit(1);
  1815. X  }
  1816. X if (ps.slavepid != getppid())
  1817. X  {
  1818. X   (void) fputs("sessname: fatal: not child of session slave\n",stderr);
  1819. X   (void) exit(1);
  1820. X  }
  1821. X if (argc == 1)
  1822. X   if (pty_get_sessname(0,uid,buf,sizeof(buf)) == -1)
  1823. X     (void) printf("session %c%c unnamed\n",ps.ext1,ps.ext2);
  1824. X   else
  1825. X     (void) printf("session %c%c: %s\n",ps.ext1,ps.ext2,buf);
  1826. X else
  1827. X  {
  1828. X   s = strlen(argv[1]) + 1;
  1829. X   if (s > 100)
  1830. X     s = 100;
  1831. X   if (pty_set_sessname(0,uid,argv[1],s) == -1)
  1832. X    {
  1833. X     (void) fputs("sessname: fatal: renaming failed\n",stderr);
  1834. X     (void) exit(1);
  1835. X    }
  1836. X  }
  1837. X  
  1838. X (void) exit(0);
  1839. X}
  1840. END_OF_FILE
  1841.   if test 1052 -ne `wc -c <'util/sessname.c'`; then
  1842.     echo shar: \"'util/sessname.c'\" unpacked with wrong size!
  1843.   fi
  1844.   # end of 'util/sessname.c'
  1845. fi
  1846. if test -f 'util/sessutil.h' -a "${1}" != "-c" ; then 
  1847.   echo shar: Will not clobber existing file \"'util/sessutil.h'\"
  1848. else
  1849.   echo shar: Extracting \"'util/sessutil.h'\" \(357 characters\)
  1850.   sed "s/^X//" >'util/sessutil.h' <<'END_OF_FILE'
  1851. X#ifndef SESSUTIL_H
  1852. X#define SESSUTIL_H
  1853. X
  1854. Xstruct pty_session
  1855. X {
  1856. X  char ext1;
  1857. X  char ext2;
  1858. X  int uid;
  1859. X  int siglerpid;
  1860. X  int masterpid;
  1861. X  int slavepid;
  1862. X }
  1863. X;
  1864. X
  1865. Xint pty_sessdir();
  1866. Xint pty_get_sess();
  1867. Xint pty_get_sessbyext();
  1868. Xint pty_set_sess();
  1869. Xint pty_get_sessname();
  1870. Xint pty_set_sessname();
  1871. Xint pty_get_rebyext();
  1872. Xint pty_set_sig();
  1873. Xint pty_unset_sig();
  1874. X
  1875. X#endif
  1876. END_OF_FILE
  1877.   if test 357 -ne `wc -c <'util/sessutil.h'`; then
  1878.     echo shar: \"'util/sessutil.h'\" unpacked with wrong size!
  1879.   fi
  1880.   # end of 'util/sessutil.h'
  1881. fi
  1882. if test -f 'util/u.1' -a "${1}" != "-c" ; then 
  1883.   echo shar: Will not clobber existing file \"'util/u.1'\"
  1884. else
  1885.   echo shar: Extracting \"'util/u.1'\" \(434 characters\)
  1886.   sed "s/^X//" >'util/u.1' <<'END_OF_FILE'
  1887. X.TH u 1
  1888. X.SH NAME
  1889. Xu \- compact list of users who are on the system
  1890. X.SH SYNOPSIS
  1891. X.B u
  1892. X.SH DESCRIPTION
  1893. X.I u
  1894. Xlists the login names of the users currently on the system in a compact,
  1895. Xsorted,
  1896. Xone-line format.
  1897. X.PP
  1898. XThe original version of this program eliminates duplicates.
  1899. X(Actually, it doesn't even do that correctly.)
  1900. XThis clone version prints exactly each user as many times
  1901. Xas /etc/utmp lists.
  1902. X.SH FILES
  1903. X/etc/utmp
  1904. X.SH "SEE ALSO"
  1905. Xwho(1)
  1906. END_OF_FILE
  1907.   if test 434 -ne `wc -c <'util/u.1'`; then
  1908.     echo shar: \"'util/u.1'\" unpacked with wrong size!
  1909.   fi
  1910.   # end of 'util/u.1'
  1911. fi
  1912. if test -f 'util/u.c' -a "${1}" != "-c" ; then 
  1913.   echo shar: Will not clobber existing file \"'util/u.c'\"
  1914. else
  1915.   echo shar: Extracting \"'util/u.c'\" \(933 characters\)
  1916.   sed "s/^X//" >'util/u.c' <<'END_OF_FILE'
  1917. X/* Public domain. */
  1918. X#include <stdio.h>
  1919. X#include <utmp.h>
  1920. X#include <strings.h>
  1921. Xextern char *malloc();
  1922. X#define PTYUTMP_FILE "/etc/utmp"
  1923. X
  1924. Xint compar(s,t)
  1925. Xchar (**s)[8];
  1926. Xchar (**t)[8];
  1927. X{
  1928. X return -strncmp(&(**s)[0],&(**t)[0],8);
  1929. X}
  1930. X
  1931. Xmain()
  1932. X{
  1933. X register FILE *fi;
  1934. X struct utmp ut;
  1935. X char (*us)[8];
  1936. X char (**up)[8];
  1937. X int lines = 0;
  1938. X int i = 0;
  1939. X if (fi = fopen(PTYUTMP_FILE,"r"))
  1940. X   while (fread((char *) &ut,sizeof(ut),1,fi))
  1941. X     if (ut.ut_name[0])
  1942. X       lines++;
  1943. X (void) fclose(fi);
  1944. X us = malloc(sizeof(*us) * (lines + 50));
  1945. X up = malloc(sizeof(*up) * (lines + 50));
  1946. X if (fi = fopen(PTYUTMP_FILE,"r"))
  1947. X   while (fread((char *) &ut,sizeof(ut),1,fi))
  1948. X     if ((ut.ut_name[0]) && (i < lines + 50))
  1949. X      {
  1950. X       (void) strncpy(us[i],ut.ut_name,8);
  1951. X       up[i] = us + i;
  1952. X       i++;
  1953. X      }
  1954. X (void) fclose(fi);
  1955. X (void) qsort(up,i,sizeof(*up),compar);
  1956. X
  1957. X while (i-- > 0)
  1958. X   (void) printf((i ? "%.8s " : "%.8s\n"),up[i]);
  1959. X
  1960. X (void) exit(0);
  1961. X}
  1962. END_OF_FILE
  1963.   if test 933 -ne `wc -c <'util/u.c'`; then
  1964.     echo shar: \"'util/u.c'\" unpacked with wrong size!
  1965.   fi
  1966.   # end of 'util/u.c'
  1967. fi
  1968. if test -f 'util/wall.1' -a "${1}" != "-c" ; then 
  1969.   echo shar: Will not clobber existing file \"'util/wall.1'\"
  1970. else
  1971.   echo shar: Extracting \"'util/wall.1'\" \(412 characters\)
  1972.   sed "s/^X//" >'util/wall.1' <<'END_OF_FILE'
  1973. X.TH wall 1
  1974. X.SH NAME
  1975. Xwall \- write to all users
  1976. X.SH SYNOPSIS
  1977. X.B wall
  1978. X.SH DESCRIPTION
  1979. X.I wall
  1980. Xprompts for a message with
  1981. X``Broadcast Message,''
  1982. Xthen reads its standard input until end-of-file.
  1983. XIt then sends this message
  1984. Xto all logged in users.
  1985. X.PP
  1986. XNaturally,
  1987. X.I mesg
  1988. Xprotections apply.
  1989. X.SH FILES
  1990. X/dev/tty*
  1991. X.br
  1992. X/etc/utmp
  1993. X.SH RESTRICTIONS
  1994. XThe message is limited to 10000 characters.
  1995. X.SH "SEE ALSO"
  1996. Xmesg(1),
  1997. Xwrite(1)
  1998. END_OF_FILE
  1999.   if test 412 -ne `wc -c <'util/wall.1'`; then
  2000.     echo shar: \"'util/wall.1'\" unpacked with wrong size!
  2001.   fi
  2002.   # end of 'util/wall.1'
  2003. fi
  2004. if test -f 'util/wall.c' -a "${1}" != "-c" ; then 
  2005.   echo shar: Will not clobber existing file \"'util/wall.c'\"
  2006. else
  2007.   echo shar: Extracting \"'util/wall.c'\" \(1577 characters\)
  2008.   sed "s/^X//" >'util/wall.c' <<'END_OF_FILE'
  2009. X/* Public domain. */
  2010. X
  2011. X#include <sys/types.h>
  2012. X#include <sys/timeb.h>
  2013. X#include <sys/file.h>
  2014. X#ifdef BSD
  2015. X#include <limits.h>
  2016. X#endif
  2017. X#include <stdio.h>
  2018. X#include <strings.h>
  2019. X#include <utmp.h>
  2020. X#include <pwd.h>
  2021. X#include <time.h>
  2022. X#include <ctype.h>
  2023. Xextern unsigned short getuid();
  2024. Xextern char *ttyname();
  2025. Xextern long time();
  2026. X#define PTYUTMP_FILE "/etc/utmp"
  2027. X
  2028. Xmain()
  2029. X{ 
  2030. X register FILE *fi;
  2031. X struct utmp ut;
  2032. X char fntty[30];
  2033. X int fd;
  2034. X char buf[10000];
  2035. X char *username;
  2036. X struct passwd *pw;
  2037. X char hostname[64];
  2038. X char *ttyn;
  2039. X long t;
  2040. X struct tm *tm;
  2041. X int r;
  2042. X int pos;
  2043. X
  2044. X if (!(pw = getpwuid((int) getuid())))
  2045. X  {
  2046. X   (void) fprintf(stderr,"write: who are you?\n");
  2047. X   (void) exit(1);
  2048. X  }
  2049. X username = pw->pw_name;
  2050. X
  2051. X (void) gethostname(hostname,sizeof(hostname));
  2052. X
  2053. X if (!(ttyn = ttyname(2)))
  2054. X  {
  2055. X   (void) fprintf(stderr,"wall: Can't find your tty\n");
  2056. X   (void) exit(1);
  2057. X  }
  2058. X
  2059. X t = time((long *) 0);
  2060. X tm = localtime(&t);
  2061. X
  2062. X (void) sprintf(buf,"\nBroadcast message from %s@%s on %s at %d:%02d ...\n\n",
  2063. X        username,hostname,ttyn + 5,tm->tm_hour,tm->tm_min);
  2064. X pos = strlen(buf);
  2065. X (void) write(1,buf + 1,pos - 1);
  2066. X while ((pos < 10000) && ((r = read(0,buf + pos,10000 - pos)) > 0))
  2067. X   pos += r;
  2068. X
  2069. X if (fi = fopen(PTYUTMP_FILE,"r"))
  2070. X   while (fread((char *) &ut,sizeof(ut),1,fi))
  2071. X     if (ut.ut_name[0])
  2072. X      {
  2073. X       (void) sprintf(fntty,"/dev/%.8s",ut.ut_line);
  2074. X       if ((fd = open(fntty,O_WRONLY)) == -1)
  2075. X         (void) fprintf(stderr,"wall: cannot write to %.8s\n",ut.ut_line);
  2076. X       else
  2077. X        {
  2078. X     (void) write(fd,buf,pos);
  2079. X         (void) close(fd);
  2080. X        }
  2081. X      }
  2082. X
  2083. X (void) exit(0);
  2084. X}
  2085. END_OF_FILE
  2086.   echo shar: 1 control character may be missing from \"'util/wall.c'\"
  2087.   if test 1577 -ne `wc -c <'util/wall.c'`; then
  2088.     echo shar: \"'util/wall.c'\" unpacked with wrong size!
  2089.   fi
  2090.   # end of 'util/wall.c'
  2091. fi
  2092. if test -f 'util/who.1' -a "${1}" != "-c" ; then 
  2093.   echo shar: Will not clobber existing file \"'util/who.1'\"
  2094. else
  2095.   echo shar: Extracting \"'util/who.1'\" \(693 characters\)
  2096.   sed "s/^X//" >'util/who.1' <<'END_OF_FILE'
  2097. X.TH who 1
  2098. X.SH NAME
  2099. Xwho \- who is on the system
  2100. X.SH SYNOPSIS
  2101. X.B who
  2102. X[
  2103. X.I file
  2104. X] [
  2105. X.B "am I"
  2106. X]
  2107. X.SH DESCRIPTION
  2108. X.I who
  2109. Xlists the login name, terminal name, and login time
  2110. Xfor each current user.
  2111. XNormally
  2112. X.I who
  2113. Xuses
  2114. X.I /etc/utmp,
  2115. Xand omits
  2116. Xlogged-out terminals.
  2117. XIf you give it a
  2118. X.I file,
  2119. Xsuch as
  2120. X/usr/adm/wtmp,
  2121. Xit will use that file instead,
  2122. Xand include logouts as lines with a blank username.
  2123. XReboots have an x in place of 
  2124. X.I ttyxx.
  2125. X.PP
  2126. XWith two arguments,
  2127. Xas in
  2128. X.I who am I
  2129. X(and also 
  2130. X.I who are you),
  2131. X.I who
  2132. Xtells who you are logged in as.
  2133. XNote that in this clone version,
  2134. X.I who
  2135. Xgives a meaningful error when its input is not a terminal.
  2136. X.SH FILES
  2137. X/etc/utmp
  2138. X.SH "SEE ALSO"
  2139. Xgetuid(2), utmp(5)
  2140. END_OF_FILE
  2141.   if test 693 -ne `wc -c <'util/who.1'`; then
  2142.     echo shar: \"'util/who.1'\" unpacked with wrong size!
  2143.   fi
  2144.   # end of 'util/who.1'
  2145. fi
  2146. if test -f 'util/who.c' -a "${1}" != "-c" ; then 
  2147.   echo shar: Will not clobber existing file \"'util/who.c'\"
  2148. else
  2149.   echo shar: Extracting \"'util/who.c'\" \(1208 characters\)
  2150.   sed "s/^X//" >'util/who.c' <<'END_OF_FILE'
  2151. X/* Public domain. */
  2152. X#include <stdio.h>
  2153. X#include <utmp.h>
  2154. X#include <strings.h>
  2155. X#include <time.h>
  2156. Xextern char *ttyname();
  2157. X#define PTYUTMP_FILE "/etc/utmp"
  2158. X
  2159. Xmain(argc,argv)
  2160. Xint argc;
  2161. Xchar *argv[];
  2162. X{
  2163. X FILE *fi;
  2164. X struct utmp ut;
  2165. X char fn[100];
  2166. X char ttyn[100];
  2167. X char hostname[120];
  2168. X int whoami = 0;
  2169. X if (argc > 3) exit(0);
  2170. X if (argc > 2)
  2171. X  {
  2172. X   whoami = 1;
  2173. X   if (!isatty(0))
  2174. X    {
  2175. X     fprintf(stderr,"who: Not a tty\n");
  2176. X     exit(1);
  2177. X    }
  2178. X   (void) strcpy(ttyn,ttyname(0) + 5);
  2179. X   (void) gethostname(hostname,120);
  2180. X  }
  2181. X if (argc == 2)
  2182. X   (void) strncpy(fn,argv[1],100);
  2183. X else
  2184. X   (void) strncpy(fn,PTYUTMP_FILE,100);
  2185. X
  2186. X if ((fi = fopen(fn,"r")) == NULL)
  2187. X  {
  2188. X   (void) sprintf(hostname,"who: %s",fn);
  2189. X   (void) perror(hostname);
  2190. X   (void) exit(1);
  2191. X  }
  2192. X
  2193. X while (fread((char *) &ut,sizeof(ut),1,fi))
  2194. X  {
  2195. X   if (ut.ut_name[0] || (argc > 1))
  2196. X     if ((!whoami) || (!strncmp(ut.ut_line,ttyn,8)))
  2197. X      {
  2198. X       if (whoami)
  2199. X     (void) printf("%s!",hostname);
  2200. X       (void) printf("%-8.8s %-8.8s%-12.12s",ut.ut_name,ut.ut_line,
  2201. X             asctime(localtime(&ut.ut_time)) + 4);
  2202. X       if (ut.ut_host[0])
  2203. X     (void) printf("    (%.16s)",ut.ut_host);
  2204. X       (void) printf("\n");
  2205. X      }
  2206. X  }
  2207. X (void) fclose(fi);
  2208. X (void) exit(0);
  2209. X}
  2210. END_OF_FILE
  2211.   if test 1208 -ne `wc -c <'util/who.c'`; then
  2212.     echo shar: \"'util/who.c'\" unpacked with wrong size!
  2213.   fi
  2214.   # end of 'util/who.c'
  2215. fi
  2216. if test -f 'util/write.1' -a "${1}" != "-c" ; then 
  2217.   echo shar: Will not clobber existing file \"'util/write.1'\"
  2218. else
  2219.   echo shar: Extracting \"'util/write.1'\" \(1761 characters\)
  2220.   sed "s/^X//" >'util/write.1' <<'END_OF_FILE'
  2221. X.TH write 1
  2222. X.SH NAME
  2223. Xwrite \- write to another user
  2224. X.SH SYNOPSIS
  2225. X.B write
  2226. X.I user
  2227. X[
  2228. X.I ttyname
  2229. X]
  2230. X.SH DESCRIPTION
  2231. X.I write
  2232. Xcopies lines from your terminal to that of
  2233. Xanother user.
  2234. XThis clone version
  2235. Xstarts and (if you don't kill the process)
  2236. Xends your message with identifying lines.
  2237. XIt also
  2238. Xprecedes each line with your username.
  2239. X.PP
  2240. XIf you want to write to a user who is logged in more than once,
  2241. Xinclude the terminal name as
  2242. X.I ttyname.
  2243. X(This reflects several failures in the pseudo-terminal model.)
  2244. X.PP
  2245. XThe other user can use
  2246. X.I mesg
  2247. Xto allow or deny
  2248. X.I write
  2249. Xpermission.
  2250. XIn many recent versions of
  2251. X.I write,
  2252. Xyou cannot write to a user unless you are also allowing messages;
  2253. Xunfortunately, this adds absolutely no security, because you can
  2254. Xturn messages right back off after starting
  2255. X.I write.
  2256. XThis clone version exhibits the right behavior:
  2257. Xit checks
  2258. X.I mesg
  2259. Xpermission on the other end
  2260. Xbefore writing each line.
  2261. X.PP
  2262. XThis version of
  2263. X.I write
  2264. Xdoes not
  2265. Xallow shell escapes.
  2266. X.PP
  2267. XThere are many popular ways of using
  2268. X.I write
  2269. X(perhaps the most common being to
  2270. Xuse
  2271. X.I talk
  2272. Xinstead).
  2273. XTypically each user ends each series of lines
  2274. Xwith a distinctive signal, such as
  2275. X``ga'' (go ahead),
  2276. Xso that the other user can type without
  2277. Xworrying about messed-up output.
  2278. XThe number of abbreviations used in
  2279. Xscreen conversation is immense.
  2280. X.PP
  2281. XThis clone version of
  2282. X.I write
  2283. Xuses the standard input,
  2284. Xrather than the standard error,
  2285. Xto determine your tty.
  2286. X.PP
  2287. X.I write
  2288. Xreplaces unprintable characters by
  2289. Xcarets upon output.
  2290. X.SH RESTRICTIONS
  2291. XLines longer than 500 characters
  2292. Xwill be split in two.
  2293. X.PP
  2294. X.I write
  2295. Xsleeps for a second after sending each line.
  2296. XThis restriction means that you can't
  2297. Xflood someone else's screen with a large text.
  2298. X.SH "SEE ALSO"
  2299. Xmesg(1),
  2300. Xwho(1),
  2301. Xmail(1)
  2302. END_OF_FILE
  2303.   if test 1761 -ne `wc -c <'util/write.1'`; then
  2304.     echo shar: \"'util/write.1'\" unpacked with wrong size!
  2305.   fi
  2306.   # end of 'util/write.1'
  2307. fi
  2308. echo shar: End of archive 5 \(of 6\).
  2309. cp /dev/null ark5isdone
  2310. MISSING=""
  2311. for I in 1 2 3 4 5 6 ; do
  2312.     if test ! -f ark${I}isdone ; then
  2313.     MISSING="${MISSING} ${I}"
  2314.     fi
  2315. done
  2316. if test "${MISSING}" = "" ; then
  2317.     echo You have unpacked all 6 archives.
  2318.     rm -f ark[1-9]isdone
  2319. else
  2320.     echo You still must unpack the following archives:
  2321.     echo "        " ${MISSING}
  2322. fi
  2323. exit 0
  2324. exit 0 # Just in case...
  2325. -- 
  2326. Please send comp.sources.unix-related mail to rsalz@uunet.uu.net.
  2327. Use a domain-based address or give alternate paths, or you may lose out.
  2328.